<!-- wyf 2022-2-16 -->
<template>
  <a-table
    :data-source="dataSource"
    :columns="columns"
    :pagination="pagination"
    :bordered="bordered"
    :scroll="scroll"
    :locale="locale.Table"
    :row-class-name="rowClassName"
    :loading="loading"
    :expanded-row-keys="expandedRowKeys"
    :expand-fixed="expandFixed"
    :default-expand-all-rows="defaultExpandAllRows"
    :children-column-name="childrenColumnName"
    :expand-row-by-click="expandRowByClick"
    :show-expand-column="showExpandColumn"
    :show-header="showHeader"
    :show-sorter-tooltip="showSorterTooltip"
    :size="size"
    :sort-directions="sortDirections"
    :transform-cell-text="transformCellText"
    :sticky="sticky"
    :table-layout="tableLayout"
    :components="components"
    :custom-header-row="customHeaderRow"
    :custom-row="customRow"
    :default-expanded-row-keys="defaultExpandedRowKeys"
    :get-popup-container="getPopupContainer"
    :indent-size="indentSize"
    :row-expandable="rowExpandable"
    @expand="expand"
    @expandedRowsChange="expandedRowsChange"
    @resizeColumn="resizeColumn"
  >
    <template v-if="$slots.bodyCell" #bodyCell="{ column ,text, record, index }">
      <slot name="bodyCell" :column="column" :text="text" :record="record" :index="index" />
    </template>
    <template v-if="$slots.headerCell" #headerCell="{ title, column }">
      <slot name="headerCell" :title="title" :column="column" />
    </template>
    <template v-if="$slots.title" #title="currentPageData">
      <slot v-if="title !== undefined" name="title" :currentPageData="currentPageData">{{ title }}</slot>
      <slot v-else name="title" />
    </template>
    <template v-if="$slots.footer" #footer="currentPageData">
      <slot v-if="footer !== undefined" name="footer" :currentPageData="currentPageData">{{ footer(currentPageData) }}</slot>
      <slot v-else name="footer" />
    </template>
    <template v-if="$slots.expandedRowRender" #expandedRowRender="{record, index, indent, expanded}">
      <slot v-if="expandedRowRender !== undefined" name="expandedRowRender">{{ expandedRowRender(record, index, indent, expanded) }}</slot>
      <slot v-else name="expandedRowRender" :record="record" :index="index" :indent="indent" :expanded="expanded" />
    </template>
    <template v-if="$slots.customFilterDropdown" #customFilterDropdown="FilterDropdownProps">
      <slot name="customFilterDropdown" :FilterDropdownProps="FilterDropdownProps" />
    </template>
    <template v-if="$slots.customFilterIcon" #customFilterIcon="{filtered, column}">
      <slot name="customFilterIcon" :filtered="filtered" :column="column" />
    </template>
    <template v-if="$slots.emptyText" #emptyText>
      <slot name="emptyText" />
    </template>
    <template v-if="$slots.summary" #summary>
      <slot name="summary" />
    </template>
    <template v-if="$slots.maxTagPlaceholder" #maxTagPlaceholder>
      <slot v-if="maxTagPlaceholder !== undefined" name="maxTagPlaceholder">{{ maxTagPlaceholder }}</slot>
      <slot v-else name="maxTagPlaceholder" />
    </template>
    <template v-if="$slots.expandIcon" #expandIcon>
      <slot v-if="expandIcon !== undefined" name="expandIcon">{{ expandIcon() }}</slot>
      <slot v-else name="expandIcon" />
    </template>
  </a-table>
</template>

<script>
import { defineComponent } from 'vue'
import { Table } from 'ant-design-vue'
export default defineComponent({
  name: 'ZTable',
  components: {
    ATable: Table
  },
  props: {
    dataSource: {
      type: Array,
      default() {
        return []
      }
    },
    columns: {
      type: Array,
      default: undefined
    },
    pagination: {
      type: [Object, Boolean],
      default: undefined
    },
    bordered: {
      type: Boolean,
      default: false
    },
    rowClassName: {
      type: Function,
      default: undefined
    },
    title: {
      type: Function,
      default: undefined
    },
    loading: {
      type: [Boolean, Object],
      default: false
    },
    components: {
      type: Object,
      default: undefined
    },
    childrenColumnName: {
      type: String,
      default: 'children'
    },
    customHeaderRow: {
      type: Function,
      default: undefined
    },
    customRow: {
      type: Function,
      default: undefined
    },
    defaultExpandAllRows: {
      type: Boolean,
      default: false
    },
    defaultExpandedRowKeys: {
      type: Array,
      default: undefined
    },
    expandedRowKeys: {
      type: Array,
      default: undefined
    },
    expandedRowRender: {
      type: Function,
      default: undefined
    },
    expandFixed: {
      type: [Boolean, String],
      default: undefined
    },
    maxTagPlaceholder: {
      type: Function,
      default: undefined
    },
    expandIcon: {
      type: Function,
      default: undefined
    },
    expandRowByClick: {
      type: Boolean,
      default: false
    },
    footer: {
      type: Function,
      default: undefined
    },
    getPopupContainer: {
      type: Function,
      default: undefined
    },
    rowExpandable: {
      type: Function,
      default: undefined
    },
    rowKey: {
      type: [String, Function],
      default: 'key'
    },
    rowSelection: {
      type: Object,
      default: null
    },
    scroll: {
      type: Object,
      default: undefined
    },
    showExpandColumn: {
      type: Boolean,
      default: true
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    showSorterTooltip: {
      type: [Boolean, Object],
      default: true
    },
    size: {
      type: String,
      default: 'default'
    },
    sortDirections: {
      type: Array,
      default() {
        return ['ascend', 'descend']
      }
    },
    tableLayout: {
      type: String,
      default: undefined
    },
    transformCellText: {
      type: Function,
      default: undefined
    },
    sticky: {
      type: [Boolean, Function],
      default: undefined
    },
    indentSize: {
      type: Number,
      default: 15
    }
  },
  methods: {
    expand(expanded, record) {
      this.$emit('expand', expanded, record)
    },
    expandedRowsChange(expandedRows) {
      this.$emit('expandedRowsChange', expandedRows)
    },
    resizeColumn(width, column) {
      this.$emit('resizeColumn', width, column)
    }
  }
})
</script>
